package de.koller.aframe.plain.gui.input;
 
import de.koller.aframe.util.thread.ICommand;
import de.koller.aframe.plain.gui.ICallableRoot;

public class SyncInputHandler implements IInputHandler {

	private final ICallableRoot callRoot;
	private final IInputHandler syncCallto;

	public SyncInputHandler( ICallableRoot callRoot, IInputHandler syncCallto ) {
		this.callRoot = callRoot;
		this.syncCallto = syncCallto;
	}

	@Override
	public void click( int x, int y ) {
		callRoot.call( new MouseClickCall( x, y ) );
	}

	@Override
	public void keyPress( int key ) {
		callRoot.call( new KeyPressCall( key ) );
	}

	@Override
	public void mouseMove( int x, int y ) {
		callRoot.call( new MouseMoveCall( x, y ) );
	}

	private class MouseMoveCall implements ICommand {
		private final int x, y;

		private MouseMoveCall( int x, int y ) {
			this.x = x;
			this.y = y;
		}

		@Override
		public void handle( Object... params ) {
			syncCallto.mouseMove( x, y );
		}

	}
	
	private class KeyPressCall implements ICommand {
		private final int key;

		private KeyPressCall( int key ) {
			this.key = key;
		}

		@Override
		public void handle( Object... params ) {
			syncCallto.keyPress( key );
		}
	}
	
	private class MouseClickCall implements ICommand {
		private final int x, y;

		private MouseClickCall( int x, int y ) {
			this.x = x;
			this.y = y;
		}

		@Override
		public void handle( Object... params ) {
			syncCallto.click( x, y );
		}

	}
	
}
